<?php
/**
 * 算法类
 * User: jinzhi<admin@end.wiki>
 * Date: 2017/10/29
 * Time: 11:18
 */
namespace core;

use exception\NotNumericException;

class Addition implements AlgorithmInterface {

    public $label = '+';

    /**
     * 加法运算
     * @param array $addends 除数
     * @throws NotNumericException [603]计算元素中有非数值异常
     * @return Number
     */
    protected function addition($addends){
        $sum = 0;
        foreach($addends as $addend){
			if(is_null($addend) || $addend == ''){
				$addend = 0;
			}
            if(!is_numeric($addend)){
                throw new NotNumericException();
            }
            $sum += $addend;
        }
        return $sum;
    }

    public function compute($params){
        return $this->addition($params);
    }
}